<template>
  <div class="twolist">
    <div class="xuanzekuang">
      <div class="xuanzekuang-title">
        <button @click="togglePanel">
          <div class="xuanzekuang-text">图例</div>
          <div class="zhankai"></div>
        </button>
        <div v-if="isPanelOpen" class="panel">
          <div class="checkbox-all">
            <div class="checkbox-1">
              <input
                type="checkbox"
                id="option1"
                value="Option 1"
                v-model="selectedOptions"
                @change="handleSelection"
              />
              <div class="option1-img"></div>
              <label for="option1">柏林工业园</label>
            </div>
            <div class="checkbox-1">
              <input
                type="checkbox"
                id="option2"
                value="Option 2"
                v-model="selectedOptions"
                @change="handleSelection"
              />
              <div class="option2-img"></div>
              <label for="option2">骨干企业</label>
            </div>
            <div class="checkbox-1">
              <input
                type="checkbox"
                id="option3"
                value="Option 3"
                v-model="selectedOptions"
                @change="handleSelection"
              />
              <div class="option3-img"></div>
              <label for="option3">其他企业</label>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="full">
      <div class="flex-container">
        <img src="../assets/楼房.png" width="40" height="40" />
        <div class="top-title">企业管理</div>
      </div>
      <div class="container">
        <div class="full-secondtitle">
          <div class="h1">工业园区概况</div>
        </div>
      </div>
      <div class="box">
        <div class="flex-container">
          <div class="flex-cyr-item">
            <div class="flex-cyr-text">
              <!-- 数字 -->
              <div class="cyr-number">{{ rate1 }}0</div>
              <!-- 文字 -->
            </div>
            <span class="cyr-text2">{{ text1 }}企业数量</span>
          </div>

          <div class="flex-cyr-item">
            <div class="flex-cyr-text">
              <!-- 数字 -->
              <div class="cyr-number">{{ rate1 }}0</div>
              <!-- 文字 -->
            </div>
            <span class="cyr-text2">{{ text1 }}厂房数量</span>
          </div>
          <div class="flex-cyr-item">
            <div class="flex-cyr-text">
              <!-- 数字 -->
              <div class="cyr-number">{{ rate1 }}0</div>
              <!-- 文字 -->
            </div>
            <span class="cyr-text2">{{ text1 }}就业人数</span>
          </div>
        </div>
      </div>
      <div class="container">
        <div class="full-secondtitle">
          <div class="h1">经济类型占比</div>
        </div>
      </div>

      <div class="flex-container">
        <div class="cht33">
          <v-chart
            id="chart33"
            ref="chart33"
            class="chart33"
            :option="option33"
          />
        </div>
      </div>
      <div class="container">
        <div class="full-secondtitle">
          <div class="h1">企业规模占比</div>
        </div>
      </div>
      <div class="cht34">
        <v-chart
          id="chart34"
          ref="chart34"
          class="chart34"
          :option="option34"
        />
      </div>
      <div class="container">
        <div class="full-secondtitle">
          <div class="h1">企业租期分布</div>
        </div>
      </div>
      <div class="cht35">
        <v-chart id="chart35" class="chart35" :option="option35" />
      </div>
    </div>
  </div>
</template>

<script >
// var chartDom = document.getElementById("main");postall
// var myChart = echarts.init(chartDom);
import * as echarts from "echarts";
import { ref, onMounted, watch } from "vue";
import axios from "axios";
import { getarticle } from "../reqeust/index";
export default {
  data() {
    return {
      // option34: {}, // 存储echarts图表的配置项
      option35: {}, // 存储echarts图表的配置项
    };
  },
  setup() {
    const isPanelOpen = ref(false);
    const togglePanel = () => {
      isPanelOpen.value = !isPanelOpen.value;
    };
    const selectedOptions = ref([]);
    const handleSelection = (event) => {
      console.log("Selected options:", selectedOptions.value);
    };
    const chart34 = ref(null);
    const option34 = ref(null);
    const chart33 = ref(null);
    const option33 = ref(null);
    async function fetchData() {
      try {
        option34.value = {
          // 根据需要配置echarts的option
          backgroundColor: "transparent",
          //   color: ["#c73232", "#8f2323"],
          legend: {
            top: "15%",
            left: "1%",
            orient: "vertical",
            textStyle: {
              color: "#ffffff",
              fontSize: 16, // 设置图例文字大小
            },
          },
          tooltip: {
            trigger: "item",
            textStyle: {
              fontSize: 16, // 设置图例文字大小
            },
          },
          series: [
            {
              name: "治安监控",
              type: "pie",
              // roseType: "radius",
              data: [
                { value: 15, name: 123 },
                { value: 20, name: 222 },
              ],
              label: {
                color: "#ffffff",
                // alignTo: "edge",
                formatter: function (params) {
                  var percent = ((params.value / 35) * 100).toFixed(0);
                  return percent + "%";
                },
                // minMargin: 50,
                edgeDistance: 10,
                lineHeight: 18,
                fontSize: 16,
                rich: {
                  time: {},
                },
              },
              labelLine: {
                length: 10,
                length2: 20,
              },
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: "rgba(0, 0, 0, 0.5)",
                },
              },
            },
          ],
        };
        option33.value = {
          // 根据需要配置echarts的option
          backgroundColor: "transparent",
          //   color: ["#c73232", "#8f2323"],
          legend: {
            top: "15%",
            left: "1%",
            orient: "vertical",
            textStyle: {
              color: "#ffffff",
              fontSize: 16, // 设置图例文字大小
            },
          },
          tooltip: {
            trigger: "item",
            textStyle: {
              fontSize: 16, // 设置图例文字大小
            },
          },
          series: [
            {
              name: "治安监控",
              type: "pie",
              // roseType: "radius",
              data: [
                { value: 15, name: 123 },
                { value: 20, name: 222 },
              ],
              label: {
                color: "#ffffff",
                // alignTo: "edge",
                formatter: function (params) {
                  var percent = ((params.value / 35) * 100).toFixed(0);
                  return percent + "%";
                },
                // minMargin: 50,
                edgeDistance: 10,
                lineHeight: 18,
                fontSize: 16,
                rich: {
                  time: {},
                },
              },
              labelLine: {
                length: 10,
                length2: 20,
              },
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: "rgba(0, 0, 0, 0.5)",
                },
              },
            },
          ],
        };
      } catch (error) {
        console.error("Failed to fetch data:", error);
      }
    }
    // 初始化echarts图表
    function initChart() {
      chart34.value = echarts.init(document.getElementById("chart34"));
      chart33.value = echarts.init(document.getElementById("chart33"));

      watch(
        option34,
        () => {
          chart34.value.setOption(option34.value);
          chart33.value.setOption(option33.value);
        },
        { deep: true }
      );
    }
    onMounted(() => {
      initChart();
      fetchData();
    });
    return {
      option34,
      option33,
      isPanelOpen,
      togglePanel,
      selectedOptions,
      handleSelection,
    };
  },
  async mounted() {
    this.getDataFromAPI();
  },
  methods: {
    async getDataFromAPI() {
      try {
        var gradientColors = [
          ["#E1E1E200", "#E1E1E2"],
          ["#E1E1E200", "#E1E1E2"],
          ["#E1E1E200", "#E1E1E2"],
          ["#EC791400", "#D57117"],
          ["#EC791400", "#D57117"],
          ["#EC791400", "#D57117"],
        ];
        this.option35 = {
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow",
            },
          },
          grid: {
            top: "0%",
            left: "0%",
            right: "4%",
            bottom: "-10%",
            containLabel: true,
          },
          xAxis: {
            type: "value",
            show: false,
          },
          yAxis: {
            type: "category",
            axisLine: {
              show: false,
            },
            axisTick: {
              show: false,
            },
            axisLabel: {
              margin: 30,
              fontSize: 16,
              align: "right",
              color: "#ffffff",
            },
            data: ["陶家浜", "陶家浜2", "陶家浜3", "陶家浜4", "陶家浜5"],
          },
          series: [
            {
              name: "2011",
              type: "bar",
              data: [18203, 23489, 29034, 104970, 131744],
              barWidth: 20,
              label: {
                show: true,
                fontSize: 16,
                color: "#ffffff",
                formatter: function (params) {
                  return params.value + "(" + ")";
                },
                position: "right",
              },
              itemStyle: {
                borderRadius: [0, 10, 10, 0],
                color: function (params) {
                  // 根据条形的索引选择对应的渐变色
                  return new echarts.graphic.LinearGradient(0, 0, 1, 0, [
                    {
                      offset: 0,
                      color: gradientColors[params.dataIndex][0],
                    },
                    {
                      offset: 1,
                      color: gradientColors[params.dataIndex][1],
                    },
                  ]);
                },
              },
            },
          ],
        };
        this.renderChart(); // 渲染图表
      } catch (error) {
        // 错误处理
        console.error(error);
      }
    },
    updateChart(newData) {
      this.option34.series[0].data = newData;
    },
    renderChart() {
      // const mychart31 = echarts.init(document.getElementById("chart34"), "dark"); // 初始化echarts图表
      // mychart31.setOption(this.option34); // 设置图表的配置项
      const myChart35 = echarts.init(document.getElementById("chart35")); // 初始化echarts图表
      myChart35.setOption(this.option35); // 设置图表的配置项
    },
  },
};
</script>
<style scoped>
.full {
  display: flex;
  flex-direction: column;
  width: 25rem;
  /* background-color: #e62f29; */
}
.top-title {
  height: 2.25rem;
  font-size: 2.25rem;
  font-weight: 600;
  font-family: "MyFontPFS", sans-serif;
  color: #ffffff;
  line-height: 2rem;
  background: linear-gradient(0deg, #5677a4 0%, rgb(255, 255, 255) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-left: 1rem;
}
.container {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}
.full-secondtitle {
  display: flex;
  align-items: center;
  background-color: #ffffff70;
  padding: 0.3rem 1rem;
}
.full-secondtitle .h1 {
  line-height: 1;
  font-size: 1.4rem;

  font-weight: 600;
  color: #ffffff;
}
.month-selector {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  right: 10%;
}
.select1 {
  height: 3rem;
  width: 3.5rem;
  text-align: center;
  font-size: 1.5rem;

  font-weight: 400;
  color: #ffffff;
  line-height: 3rem;
}
.select1 option {
  background-color: transparent;
}
select {
  border-radius: 10px;
  border: 2px solid rgb(0, 255, 255); /* 设置边框宽度和颜色为蓝色 */
  box-shadow: 0 0 20px rgb(0, 208, 255); /* 添加阴影效果 */
  transition: border-color 0.3s, box-shadow 0.3s; /* 添加过渡效果，使改变边框和阴影时平滑过渡 */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  color: #ffffff;
  background-color: transparent;
}
option {
  background-color: transparent;
  color: #000000;
  border: 2px solid rgb(0, 255, 255);
  box-shadow: 0 0 20px rgb(0, 208, 255);
}
select:focus {
  /* color: #000000; */
  outline: none;
}
select::-ms-expand {
  display: none;
}
select::-webkit-outer-spin-button,
select::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.right-top {
  align-self: flex-start; /* 靠右对齐 */
  margin-left: 1rem;
}
.box {
  width: 25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.flex-container {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  flex-grow: 1;
  width: 25rem;
  border: 0.08rem solid rgba(255, 255, 255, 0.575);
  padding: 0.3rem 1rem;
}
.flex-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex-wrap: nowrap;
  /* margin: auto; */
  flex-grow: 1;
  flex-basis: 33.33%;
}
.image {
  flex-flow: 1;
}

.number {
  font-size: 2.2rem;

  font-weight: 600;
  color: #f2f1f1;
}
.text {
  font-size: 1.2rem;

  font-weight: 400;
  color: #d9d9d9;
}
.cht34 {
  width: 25rem;
  height: 9.4rem;
  border: 0.08rem solid rgba(255, 255, 255, 0.575);
}
.cht33 {
  margin-top: -1.2rem;
  width: 24rem;
  height: 9.4rem;
}
.cht35 {
  width: 25rem;
  height: 11.5rem;
  border: 0.08rem solid rgba(255, 255, 255, 0.575);
}
.chart34 {
  width: 25rem;
  height: 9.4rem;
}
.chart33 {
  width: 24rem;
  height: 9.4rem;
}

.chart35 {
  width: 25rem;
  height: 11.5rem;
}
.flex-cyr-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex-wrap: nowrap;
  margin-left: 1rem;
}
.flex-cyr-text1 {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
}
.flex-cyr-text {
  display: flex;
  flex-direction: row;
}
.cyr-text1 {
  display: flex;
  align-items: flex-end;
  font-size: 1.1rem;

  font-weight: 400;
  color: #ffffff;
}
.cyr-text2 {
  font-size: 1.1rem;

  font-weight: 400;
  color: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 6.8rem;
  height: 1.5rem;
}
.cyr-h3 {
  font-size: 1rem;

  font-weight: 400;
  color: #ffffff;
  border: 0.1rem solid rgba(255, 255, 255, 0.805);
  border-radius: 0.2rem;
  position: absolute;
  padding: 0.1rem 0.5rem;
  top: 0.5rem;
  right: 0.5rem;
}
.cyr-number {
  font-size: 2.25rem;

  font-weight: 600;
  color: #ffffff;
  line-height: 1;
  padding: 0.4rem 0rem;
}
.twolist {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
}
.xuanzekuang {
  border: 0.08rem solid rgba(255, 255, 255, 0.575);
  border-radius: 0.25rem;
  margin-right: 1rem;
  padding: 0.2rem;
}
.panel {
  padding: 10px;
}
.zhankai {
  width: 0.9rem;
  height: 0.9rem;
  background-image: url("../assets/放大.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  text-align: center;
}
.xuanzekuang-title button {
  padding: 0.3rem;
  display: flex;
  flex-direction: row;
  background: transparent;
  background-color: #006aff41;
  border-radius: 5px;
  border: none;
}
.xuanzekuang-text {
  width: 11.625rem;
}
.option1-img {
  margin-left: 0.5rem;
  margin-right: 0.5rem;
  width: 0.9rem;
  height: 0.8rem;
  background-image: url("../assets/展开图片1.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  text-align: center;
}
.option2-img {
  margin-left: 0.5rem;
  margin-right: 0.5rem;
  width: 0.9rem;
  height: 0.8rem;
  background-image: url("../assets/展开图片2.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  text-align: center;
}
.option3-img {
  margin-left: 0.5rem;
  margin-right: 0.5rem;
  width: 0.9rem;
  height: 0.8rem;
  background-image: url("../assets/展开图片3.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  text-align: center;
}
.checkbox-all {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}
.checkbox-1 {
  padding: 0 0.5rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 11rem;
  border: 0.08rem solid rgba(255, 255, 255, 0.575);
  border-radius: 0.25rem;
}
.checkbox-1 label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #ffffff;
}
</style>